import time

import logo.Mlog
from match.font import get_plz
# from process.Copy import Copy
from process.chooseCharacter import chooseCharacter
from taskPro import taskPro


class House:
    def __init__(self, cy):
        self.cy = cy

    cy: any= None
    is_ok: bool = False

    yg_ok: bool = False
    cut_role: bool = False
    repairEquip_ok: bool = False
    goToBuWanJia_ok: bool = False

    def enter(self):
        logo.Mlog.logger.error(f"进入 赛利亚房间 状态")
        # 选择角色
        self.cy.is_at_town = True
        self.cy.times.reset()
        while True:
            self.cy.role = self.cy.user.get_brick_roles()
            if self.cy.role is None:
                logo.Mlog.logger.debug("任务全部完成了拉")
                return
            # logo.Mlog.logger.debug(f"运行 赛利亚房间 状态")
            self.cut_role = chooseCharacter(self.cy.role.index)
            if self.cut_role:
                logo.Mlog.logger.debug(f"第一次切换角色成功{self.cy.role.job}")
                time.sleep(10)
            else:
                logo.Mlog.logger.debug(f"第一次切换角色失败")
            # if self.cut_role:
            # ast = taskPro.getAction("repairEquip")
            # self.repairEquip_ok = ast.click()
            # if self.cut_role:
            #     logo.Mlog.logger.debug(f"修理准备成功")
            # else:
            #     logo.Mlog.logger.debug(f"修理准备失败")
            # self.cut_role=True
            if self.cut_role:
                # 检测遥感坐标
                # self.cy.player.yg.get_yg()
                while self.cy.player.yg.is_ok:
                    self.yg_ok = self.cy.player.yg.get_yg2()
                    if self.yg_ok:
                        logo.Mlog.logger.debug(f"获取遥感成功")
                        self.cy.player.yg.right_move(0.5)
                        time.sleep(0.5)
                    else:
                        logo.Mlog.logger.debug(f"获取遥感失败")
                else:
                    self.yg_ok = True
                # return
            if self.cut_role and not self.cy.player.yg.is_ok:
                ast = taskPro.getAction("goToBuWanJia")
                self.goToBuWanJia_ok = ast.click()
                if self.goToBuWanJia_ok:
                    # 返回城镇成功，进入切换角色状态
                    plz = get_plz()
                    time.sleep(0.5)
                    logo.Mlog.logger.debug(f"进入 布万家 疲劳值 {plz},")
                    if plz == 0:
                        action = taskPro.getAction("backTown2")
                        action.click()
                        logo.Mlog.logger.debug(f"进入 布万家 失败 没有疲劳值了 {plz},切换角色")
                        continue
                    else:
                        ast = taskPro.getAction("fightBegen")
                        self.goToBuWanJia_ok = ast.click()
                        self.cy.sm.transition_to("et")
                        self.cy.is_at_town = False
                        logo.Mlog.logger.debug(f"进入 布万家 成功")
                        return
            # logo.Mlog.logger.debug(f"切换角色动作 全部结束")

    def run(self):
        pass

    def exit(self):
        logo.Mlog.logger.debug(f"退出 赛利亚房间 状态")
